package com.gwnet.rider.controller;


import com.gwnet.common.core.domain.ResponseResult;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.rider.domain.RiderUser;
import com.gwnet.rider.domain.bo.WorkStatusBO;
import com.gwnet.rider.service.RiderUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 骑手基础信息表 前端控制器
 * </p>
 *
 * @author WangLiang
 * @since 2024-07-30
 */
@Slf4j
@RestController
@RequestMapping("/riderUser")
public class RiderUserController {


    private final RiderUserService riderUserService;

    public RiderUserController(RiderUserService riderUserService) {
        this.riderUserService = riderUserService;
    }

    /**
     * 根据当前登录用户，获取骑手基本信息
     * @return
     */
    @PostMapping("/view")
    public ResponseResult<RiderUser> view(){
        Long userId = LoginHelper.getLoginUser().getUserId();
        log.info("《login》======RiderId:{}",userId);
        RiderUser riderUser = riderUserService.getById(userId);
        // 密码置空
        riderUser.setLoginPassword(null);
        return ResponseResult.success(riderUser);
    }

    /**
     * 修改接单状态
     * @param workStatusBO 修改接单状态
     * @return
     */
    @PostMapping("/workStatus")
    public ResponseResult<Boolean> changeWorkStatus(@RequestBody WorkStatusBO workStatusBO){
        Long userId = LoginHelper.getLoginUser().getUserId();
        RiderUser riderUser = riderUserService.getById(userId);
        riderUser.setWorkStatus(workStatusBO.getWorkStatus());
        boolean update = riderUserService.updateById(riderUser);
        return ResponseResult.success(update);
    }
}

